﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PdfLibrary
{
    public class PdfNullable<T>
    {
        public bool HadValue;
        public T Value;

        public PdfNullable()
        {
            HadValue = false;
        }

        public PdfNullable(T value, bool hadValue = true)
        {
            Value = value;
            HadValue = hadValue;
        }

        public T GetRequiredValue(Exception exception = null)
        {
            if (!HadValue)
            {
                if(exception == null)
                    throw new Exception("Missing required value!");
                else
                    throw exception;
            }

            return Value;
        }
    }
}
